<script type="text/javascript">
function mod_all_checkbox(class_name) {
    var i = 1;
    $('.'+class_name).each(function() {
        if (i==1) {
            if (this.checked == true) {
                i = 2;
            } else {
                i = 3;
            }
        }

        if (i == 3) {
            this.checked = false;
        } else {
            this.checked = true;
        }
    });
}

function change_check_all_status(class_name, check_all_id) {
    status = true;
    $('.'+class_name).each(function() {
        if (this.id == check_all_id) {
            check_all = this;
        } else {
            if (this.checked == false) {
                status = false;
            }
        }
    });
    if (status) {
        check_all.checked = true;
    } else {
        check_all.checked = false;
    }
}

function delete_users() {
    var ids = '';
    $("input[@type=checkbox]:checked").each(function() {
        if (this.value != '') {
            ids = ids + this.value;
        }
    });
    if (ids == '') {
        show_noticemessage('<?php __e('No conversations selected.'); ?>');
    } else {
        showItem('confirm_delete');
    }
}

function delete_users_now() {
    var ids = '';
    $("input[@type=checkbox]:checked").each(function() {
        if (this.value != '') {
            ids = ids + this.value + '|';
        }
    });
    alert(ids);
}
</script>
<div id="content">
    <ul class="inlinelist">
        <li class="prominent"><?php echo $html->admin_link(__('Create a new group'), '/groups/group_new'); ?></li>
    </ul>
<?php
if (!empty($groups)) {
?>
<p class="u">  </p>
  <form action="Users" id="list" method="post">
    <div style="display: none;" id="confirm_delete" class="d">
      <p class="warning"> <b> Are you sure you want to delete selected users? <br>
        <span class="err"> All email in the user accounts will be lost.</span> </b> <br>
        Once a user has been deleted, you must wait five days<br>
        before creating another account with the same username. </p>
      <input type="submit" name="delete" value="Delete users and emails">
      <input value="Cancel" type="button" name="Button" onclick="hideItem('confirm_delete');">
    </div>
    <table>
      <tr>
        <th colspan="6" class="tablebar">
<!--<input type="button" value="<?php __e('Send message'); ?>" onclick="show_noticemessage('<?php __e('No conversations selected.'); ?>');">-->&nbsp;</th>
      </tr>
      <tr>
<th>
<!--
<input value="" type="checkbox" name="select_all" id="select_all" class="group_checkbox" onclick="mod_all_checkbox('group_checkbox');">
-->
</th>
        <th> <?php __e('Group'); ?> </th>
        <th> <?php __e('Members'); ?>   </th>
        <th> <?php __e('Posts count'); ?>  </th>
        <th> <?php __e('Action'); ?>  </th>
      </tr>

<?php
    foreach($groups as $group) {

    if ($group->id != 1) {
        $user_count = get_group_user_count($group->id);
        $posts_count = get_group_user_posts_count($group->id);
        if (empty($user_count)) {
            $onclick = array();
        } else {
            $onclick = array('onclick'=>'alert(\'' . __('There are some users in this group, if you want to delete this group, delete the users first.') .  '\'); return false;');
        }
        $action = $html->admin_link(__('Delete'), "/groups/delete_group/$group->id/", $onclick);
    } else {
        $user_count = '';
        $posts_count = '';
        $action = '';
    }
?>
      <tr>
<td>
<?php
        if (!$group->is_anonymous) {
?>
<!--
<input value="true" type="checkbox" name="group_id[]" class="group_checkbox" onclick="change_check_all_status('group_checkbox', 'select_all');">
-->
<?php
}
?></td>

        <td>
<?php
        echo $html->admin_link(__($group->title), '/groups/group_edit/' . $group->id);
        if ($group->is_anonymous) {
            echo ' <span class="u">(', __('This is a anonymous user group'), ')</span>';
        }
?></td>
        <td><?php echo $user_count; ?></td>
        <td><?php echo $posts_count; ?></td>
        <td><?php echo $action; ?></td>
      </tr>
<?php
    }
?>
      <tr>
        <th colspan="6" class="tablebar">
<!--<input type="button" value="<?php __e('Send message'); ?>" onclick="show_noticemessage('<?php __e('No conversations selected.'); ?>');">-->&nbsp;</th>
      </tr>
    </table>
<?php
}
?>
  </form>
</div>
